//
//  CooperateController.m
//  i5db
//
//  Created by iMuse on 15-5-11.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "CooperateController.h"
#import "PullTableView.h"
#import "CooperateDetailController.h"
#import "AppCenter.h"
#import "MJRefresh.h"
#define cellHeight 60

@interface CooperateController ()
{
    UITableView * pullTableView;
    NSArray       * dataArray;
}

@end

@implementation CooperateController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"合作";
        dataArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"1",@"2",@"3",@"4",@"5",@"1",@"2",@"3",@"4",@"5", nil];
    }
    return self;
}

-(void) initSearchBar
{
    [super initSearchBar];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self initSearchBar];
    
    pullTableView = [UITableView newAutoLayoutView];
    pullTableView.dataSource = self;
    pullTableView.delegate = self;
    [self.view addSubview:pullTableView];
    
   
    __weak typeof(self) weakSelf = self;
    
    [pullTableView addLegendFooterWithRefreshingBlock:^{
        [weakSelf loadMoreData];
    }];
    
    
    [pullTableView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}
-(void)loadMoreData
{
    NSLog(@"下拉加载更多");
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return dataArray.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return cellHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString* identifier = @"i5dbIndefter";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    UIView  *   contentView     = nil;
    UILabel *   spaceLine       = nil;
    UIImageView * headImageView = nil;
    
    UILabel     * titleLabel    = nil;
    UILabel     * companyLabel  = nil;
    UIImageView * locaImageView = nil;
    UILabel     * cityLabel     = nil;
    
    UILabel     * hotLabel      = nil;
    UIImageView * hotImageView  = nil;
    
    tableView.separatorStyle = NO;
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:identifier] ;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        spaceLine = [UILabel newAutoLayoutView];
        spaceLine.backgroundColor = [AppCenter color:@"235,235,241,1"];
        [cell.contentView addSubview:spaceLine];
        [spaceLine autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
        [spaceLine autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
        [spaceLine autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
        [spaceLine autoSetDimension:ALDimensionHeight toSize:5];
        
        contentView = [UIView newAutoLayoutView];
        [cell.contentView addSubview:contentView];
        [contentView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 5, 0)];
        
        headImageView = [UIImageView newAutoLayoutView];
        headImageView.image = [UIImage imageNamed:@"shui.png"];
        headImageView.contentMode = UIViewContentModeScaleAspectFit;
        headImageView.tag = 1;
    
        [contentView addSubview:headImageView];
        [headImageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
        [headImageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
        [headImageView autoSetDimensionsToSize:CGSizeMake(40, 40)];
        
        titleLabel      = [UILabel newAutoLayoutView];
        titleLabel.text = @"流量置换流量置换流量置";
        titleLabel.numberOfLines = 0;
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.tag  = 2;
        [contentView addSubview:titleLabel];
        
        [titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
        [titleLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:100];
        [titleLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:headImageView withOffset:10];
        [titleLabel autoSetDimension:ALDimensionHeight toSize:cellHeight/2];
        
        companyLabel = [UILabel newAutoLayoutView];
        companyLabel.tag = 3;
        companyLabel.text = @"慧聪-电子汽车网";
        companyLabel.font = [UIFont systemFontOfSize:12];
        companyLabel.textColor = [AppCenter color:@"126,126,126,1"];
        [contentView addSubview:companyLabel];
        
        [companyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:titleLabel withOffset:0];
        [companyLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:headImageView withOffset:10];
        [companyLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:100];
        [companyLabel autoSetDimension:ALDimensionHeight toSize:20];
        
        cityLabel = [UILabel newAutoLayoutView];
        cityLabel.tag = 4;
        cityLabel.text = @"全国";
        cityLabel.font = [UIFont systemFontOfSize:10];
        cityLabel.textColor = companyLabel.textColor;
        [cell.contentView addSubview:cityLabel];
        [cityLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [cityLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
        
        locaImageView = [UIImageView newAutoLayoutView];
        locaImageView.image = [UIImage imageNamed:@"fujin.png"];
        [contentView addSubview:locaImageView];
        [locaImageView autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:cityLabel withOffset:-3];
        [locaImageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
        [locaImageView autoSetDimensionsToSize:CGSizeMake(12, 12)];
        
        hotLabel = [UILabel newAutoLayoutView];
        hotLabel.text = @"90";
        hotLabel.textColor = [UIColor redColor];
        hotLabel.tag = 5;
        hotLabel.font = [UIFont systemFontOfSize:10];
        [contentView addSubview:hotLabel];
        [hotLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [hotLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:cityLabel withOffset:10];
        
        hotImageView = [UIImageView newAutoLayoutView];
        hotImageView.image = [UIImage imageNamed:@"vipBizIcon102_1.png"];
        [contentView addSubview:hotImageView];
        [hotImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locaImageView withOffset:8];
        [hotImageView autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:hotLabel withOffset:-8];
        [hotImageView autoSetDimensionsToSize:CGSizeMake(12, 12)];
        
    }else
    {
       
        headImageView = (UIImageView*)[contentView viewWithTag:1];
        titleLabel    = (UILabel*)[contentView viewWithTag:2];
        companyLabel  = (UILabel*)[contentView viewWithTag:3];
        cityLabel     = (UILabel*)[contentView viewWithTag:4];
        hotLabel      = (UILabel*)[contentView viewWithTag:5];
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CooperateDetailController* controller = [[CooperateDetailController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
   
}



@end
